import { createRouter, createWebHistory } from 'vue-router'
import LayoutIndex from '@/views/layout/LayoutIndex.vue'
import LoginIndex from '@/views/login/LoginIndex.vue'
import HomeIndex from '@/views/home/HomeIndex.vue'
import CategoryIndex from '@/views/category/CategoryIndex.vue'
import subcategoryIndex from '@/views/subcategory/subcategoryIndex.vue'
import DetailIndex from '@/views/detail/DetailIndex.vue'
import CartListIndex from '@/views/cartlist/CartListIndex.vue'
import CheckOrder from '@/views/order/CheckOrder.vue'
import PayIndex from '@/views/pay/PayIndex.vue'
import PayBack from '@/views/pay/PayBack.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      component: LoginIndex,
    },
    {
      // 二级路由路径为空，当一级路由渲染时，二级路由也能得到渲染。
      path: '/',
      component: LayoutIndex,
      children: [
        {
          path: '',
          component: HomeIndex
        },
        {
          path: 'category/:id',
          component: CategoryIndex
        },
        {
          path: 'category/sub/:id',
          component: subcategoryIndex
        },
        {
          path: 'detail/:id',
          component: DetailIndex
        },
        {
          path: 'cartlist',
          component: CartListIndex
        },
        {
          path: 'order',
          component: CheckOrder
        },
        {
          path: 'pay',
          component: PayIndex
        },
        {
          path: 'paycallback',
          component: PayBack
        }

      ]
    }
  ],
  // 设置路由切换时,页面滚动条的行为。
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
